<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 3.9.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="https://fonts.loli.net/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"monocy.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":true,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":true,"nav":null,"activeClass":"valine"},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":false,"top_n_per_article":5,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="前言其实先前有写过一篇《发布一个 vue 包》，不过对于“极简主义者”来说，该文章还是显得有些复杂，毕竟需要配置“复杂”的 webpack。那么有没有一种简单上手、开箱即用的方法呢？答案是有的，vue-cli 已经完美的考虑到了这些问题，此处就介绍如何使用 vue-cli 来搭建一个完整的发包环境。  注：此处的 vue-cli 指的是 @vue/cli ，为 3.x 版本。">
<meta name="keywords" content="Vue">
<meta property="og:type" content="article">
<meta property="og:title" content="使用 vue-cli 发布一个完善的包">
<meta property="og:url" content="https://monocy.gitee.io/2019/07/11/使用-vue-cli-发布一个完善的包/index.html">
<meta property="og:site_name" content="沐光">
<meta property="og:description" content="前言其实先前有写过一篇《发布一个 vue 包》，不过对于“极简主义者”来说，该文章还是显得有些复杂，毕竟需要配置“复杂”的 webpack。那么有没有一种简单上手、开箱即用的方法呢？答案是有的，vue-cli 已经完美的考虑到了这些问题，此处就介绍如何使用 vue-cli 来搭建一个完整的发包环境。  注：此处的 vue-cli 指的是 @vue/cli ，为 3.x 版本。">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2020-08-16T09:34:09.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用 vue-cli 发布一个完善的包">
<meta name="twitter:description" content="前言其实先前有写过一篇《发布一个 vue 包》，不过对于“极简主义者”来说，该文章还是显得有些复杂，毕竟需要配置“复杂”的 webpack。那么有没有一种简单上手、开箱即用的方法呢？答案是有的，vue-cli 已经完美的考虑到了这些问题，此处就介绍如何使用 vue-cli 来搭建一个完整的发包环境。  注：此处的 vue-cli 指的是 @vue/cli ，为 3.x 版本。">

<link rel="canonical" href="https://monocy.gitee.io/2019/07/11/使用-vue-cli-发布一个完善的包/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>使用 vue-cli 发布一个完善的包 | 沐光</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">沐光</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">记录在前端之路的点点滴滴</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">31</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">15</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">61</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/kazehaiya" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://monocy.gitee.io/2019/07/11/使用-vue-cli-发布一个完善的包/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="蔡胤">
      <meta itemprop="description" content="Just do IT!">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="沐光">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          使用 vue-cli 发布一个完善的包
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-08-16 17:34:09" itemprop="dateModified" datetime="2020-08-16T17:34:09+08:00">2020-08-16</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Vue/" itemprop="url" rel="index"><span itemprop="name">Vue</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2019/07/11/使用-vue-cli-发布一个完善的包/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2019/07/11/使用-vue-cli-发布一个完善的包/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>4.5k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>4 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>其实先前有写过一篇《发布一个 vue 包》，不过对于“极简主义者”来说，该文章还是显得有些复杂，毕竟需要配置“复杂”的 webpack。那么有没有一种简单上手、开箱即用的方法呢？答案是有的，vue-cli 已经完美的考虑到了这些问题，此处就介绍如何使用 vue-cli 来搭建一个完整的发包环境。</p>
<blockquote>
<p>注：此处的 vue-cli 指的是 @vue/cli ，为 3.x 版本。</p>
</blockquote>
<a id="more"></a>
<h3 id="目标"><a href="#目标" class="headerlink" title="目标"></a>目标</h3><p>我们的最终目标是发布的包、测试环境和包的使用文档，此可概括为：项目构建环境和项目使用文档。由于 vue-cli 可以手动配置项目需要的环境，因此在项目构建环境部分此处仅记录 vue-cli 的部分配置选项和相关解释，整体的项目结构和先前的基本一致。</p>
<p>然而文档方面因为 vue-cli 没有做相应的支持，因此我们需要找一个能识别 vue 组件的文档库，个人建议首选 vuepress，其次可以尝试 docsify 或者其余能够支持 vue 的文档网站生成工具（当然自己造对应轮子也是可以的）。</p>
<h3 id="项目环境构建"><a href="#项目环境构建" class="headerlink" title="项目环境构建"></a>项目环境构建</h3><p>使用 vue-cli 创建一个项目，此处就以 vue-cli-plugin-demo 做为例子。直接使用 vue create 创建项目，然后选择 Manully select features，之后选择的内容如下图：</p>
<p><img data-src="/images/vue-cli-init-config.png" alt="vue-cli 配置"></p>
<p>这里解释一下其中部分选项的选择的原因：</p>
<h4 id="TS-的-Class-风格支持"><a href="#TS-的-Class-风格支持" class="headerlink" title="TS 的 Class 风格支持"></a>TS 的 Class 风格支持</h4><p>因为 vue3 相对于 vue2 版本有比较大的变动，至于 vue2 所支持的 class 风格的 TS 写法在 vue3 中可能不怎么支持，因此现有项目是否使用 Class 风格可能会有些争议（主要是担心写习惯后到时候不太好切换写法）。</p>
<p>个人建议使用，毕竟单纯的 TS 写法在 vue2 中的会稍显难受，装饰器的写法要稍微舒服一些。此外，多学习一些新知识总归是对自己有好处。</p>
<h4 id="TS-使用-eslint-standard"><a href="#TS-使用-eslint-standard" class="headerlink" title="TS 使用 eslint-standard"></a>TS 使用 eslint-standard</h4><p>有人会问为什么创建项目时不直接选 TSlint 作为校验规则呢？这其实也是有原因的。可以上网对比一下 ESlint 和 TSlint ，你会发现 ESlint 的校验规则相对来说更细致，且更完全。此外，TypeScript 官方都决定迁移 TSlint 至 typescript-eslint，那我们还有什么理由坚持 TSlint 了呢？嘿嘿～</p>
<div class="note info">
            <p>The TypeScript Team themselves also announced their plans to move the TypeScript codebase from TSLint to typescript-eslint, and they have been big supporters of this project. More details at <a href="https://github.com/microsoft/TypeScript/issues/30553" target="_blank" rel="noopener">https://github.com/microsoft/TypeScript/issues/30553</a></p>
          </div>
<h4 id="其余部分"><a href="#其余部分" class="headerlink" title="其余部分"></a>其余部分</h4><p>单元测试部分因为我仅仅了解 Mocha 的部分内容，因此选择的是 Mocha，熟悉 Jest 的可以选 Jest；至于勾选 vue-router 和 vuex，这个是对于运行 devServer 做的一些配置；然后是 vue-router 不选择 history 模式，这个仁者见仁，智者见智吧，毕竟 lib 发包不走这个。</p>
<h3 id="项目配置"><a href="#项目配置" class="headerlink" title="项目配置"></a>项目配置</h3><h4 id="结构配置"><a href="#结构配置" class="headerlink" title="结构配置"></a>结构配置</h4><p>过滤掉默认生成的并且不做修改的部分，最终项目的结构大致为</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">vue-cli-plugin-demo</span><br><span class="line">├── components.json</span><br><span class="line">├── docs</span><br><span class="line">├── packages</span><br><span class="line">├── src</span><br><span class="line">|  ├── App.vue</span><br><span class="line">|  ├── components</span><br><span class="line">|  ├── entry.js</span><br><span class="line">|  ├── main.js</span><br><span class="line">|  ├── mixins</span><br><span class="line">|  ├── router.js</span><br><span class="line">|  ├── store.js</span><br><span class="line">|  ├── views</span><br><span class="line">|  └── types</span><br><span class="line">├── types</span><br><span class="line">|  └── index.d.ts</span><br><span class="line">├── vue.config.js</span><br><span class="line">├── tsconfig.json</span><br><span class="line">├── webpack.component.js</span><br><span class="line">└── yarn.lock</span><br></pre></td></tr></table></figure>
<p>其中 docs 为文档的文件夹，然后 components.json 、webpack.component.js 和 src/entry.js 主要为了按需引入而做的单独打包处理，其次在根目录和 src 文件夹内都添加了一个 types 文件，最后在根目录下建立了一个 packages 文件夹作为发包组件的结构。接下来我们一步步来搭建我们自己的 vue 包。</p>
<blockquote>
<p>整体结构参考 element-ui 的项目结构</p>
</blockquote>
<h4 id="配置-tsconfig-json-和-vue-config-js"><a href="#配置-tsconfig-json-和-vue-config-js" class="headerlink" title="配置 tsconfig.json 和 vue.config.js"></a>配置 tsconfig.json 和 vue.config.js</h4><p>tsconfig.json 内的配置内容不是很多，仅配置以下信息：</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">"jsxFactory": "h", // 简写 jsx 的 render 函数</span><br><span class="line">"paths": [         // 配置 import 引入的路径索引，视情况扩展</span><br><span class="line">  <span class="comment">// ...,</span></span><br><span class="line">  "@views/*": [</span><br><span class="line">    <span class="string">"src/views/*"</span></span><br><span class="line">  ]</span><br><span class="line">],</span><br><span class="line">"pretty": true,    // 为错误消息设置样式</span><br><span class="line">"includes": [      // 添加需要 ts 校验的文件</span><br><span class="line">  <span class="comment">// ...</span></span><br><span class="line">  "packages/**/*.ts",</span><br><span class="line">  "packages/**/*.tsx",</span><br><span class="line">  <span class="string">"packages/**/*.vue"</span></span><br><span class="line">]</span><br></pre></td></tr></table></figure>
<p>vue.config.js 内的配置如下：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> path = <span class="built_in">require</span>(<span class="string">'path'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 配置公共请求路径</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">resolve</span> (<span class="params">dir</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> path.join(__dirname, dir)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  lintOnSave: <span class="literal">true</span>,</span><br><span class="line">  productionSourceMap: <span class="literal">false</span>,</span><br><span class="line">  chainWebpack: <span class="function"><span class="params">config</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// 设置 output 的默认 export 值</span></span><br><span class="line">    config.output.libraryExport(<span class="string">'default'</span>)</span><br><span class="line">    <span class="comment">// 新增部分别名，视情况扩展</span></span><br><span class="line">    config.resolve.alias</span><br><span class="line">      .set(<span class="string">'@'</span>, resolve(<span class="string">'src'</span>))</span><br><span class="line">      .set(<span class="string">'@views'</span>, resolve(<span class="string">'src/views'</span>))</span><br><span class="line">      <span class="comment">// ...</span></span><br><span class="line">    <span class="comment">// 新增 js 的 exclude 内容</span></span><br><span class="line">    config.module.rule(<span class="string">'js'</span>).exclude.add([resolve(<span class="string">'lib'</span>), resolve(<span class="string">'dist'</span>)])</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p><strong>注：</strong> 两文件内的别名扩展需要保持一致。除了配置别名外，另一个<strong>需要关注的部分</strong>是修改 rule(‘js’) 部分的配置，否则后面测试自己打包好的 lib 文件会报错。</p>
</blockquote>
<h4 id="packages-包写法"><a href="#packages-包写法" class="headerlink" title="packages 包写法"></a>packages 包写法</h4><p>packages 包用于存放我们编写的包组件，我们统一其每一项的结构为：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">/*...*/vue-cli-project-demo/packages</span><br><span class="line">└── button</span><br><span class="line">   ├── index.ts</span><br><span class="line">   └── src</span><br><span class="line">      └── main.vue</span><br></pre></td></tr></table></figure>
<p>这么写的原因在于方便按需打包，使用统一的格式利于我们抽象对应的函数方法，同时也利于项目的维护。其中 index.ts 用于暴露 src 中的 vue 文件和其对应的 install 扩展方法。</p>
<blockquote>
<p>index.ts 内没有必要对单文件进行 install 扩展，除非需要规范化对应 component 的标签值，比如：element-ui 单文件引入的是 Button，没有 el 前缀，用 Vue.use 就是为了补充上前缀，内部走 Vue.component 方法。</p>
</blockquote>
<blockquote>
<p>个人建议：保证导出的组件的 name 值符合总体规范即可，并不需要一定走此配置的格式。</p>
</blockquote>
<h4 id="打包配置"><a href="#打包配置" class="headerlink" title="打包配置"></a>打包配置</h4><p>这里使用的是 vue-cli 提供的 lib 打包方式，基本不用额外的 webpack 配置，命令为：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vue-cli-service build --target lib --name myLib [entry]</span><br></pre></td></tr></table></figure>
<p>因此我们可以改造 package.json 如下：</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">"scripts": &#123;</span><br><span class="line">  "dev": "vue-cli-service serve --open",</span><br><span class="line">  "build": "vue-cli-service build --target lib --dest lib ./src/entry.ts &amp;&amp; yarn removeHtml",</span><br><span class="line">  "removeHtml": "rm ./lib/*.html",</span><br><span class="line">  "lint:js": "vue-cli-service lint",</span><br><span class="line">  "lint:css": "npx stylelint src packages --fix",</span><br><span class="line">  "test:unit": "vue-cli-service test:unit"</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>因为构建 lib 包会默认生成一个 html 文件，在此我做了删除。此外添加了 stylelint 的一些配置。demo 内还规范了发包上传的内容以及 commit 时的校验配置，可视情况添加。</p>
<p>此外如果更规范一点，我们可以写上作者，写作者等配置（可参考 demo）。</p>
<h4 id="dev-环境配置"><a href="#dev-环境配置" class="headerlink" title="dev 环境配置"></a>dev 环境配置</h4><p>开发环境需要配置的东西基本没有，这里仅仅介绍一下如何引用打包文件。此处有两种情况：</p>
<p>在开发包的阶段，我们直接引用 entry.ts 文件即可，当测试生成的包时，我们引用 lib 内的生成的文件。如：</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 开发时测试用</span></span><br><span class="line"><span class="keyword">import</span> MyComponents <span class="keyword">from</span> <span class="string">'./entry'</span>;</span><br><span class="line"><span class="comment">// 构建完测试用</span></span><br><span class="line"><span class="keyword">import</span> MyComponents <span class="keyword">from</span> <span class="string">'@lib/vue-cli-project-demo.umd'</span>;</span><br></pre></td></tr></table></figure>
<p>此时我们需要配置对应 js 文件的 module 扩展，如 demo 内的 global.d.ts 的声明：</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">declare</span> <span class="keyword">module</span> "@lib/*" &#123;</span><br><span class="line">  <span class="keyword">import</span> Vue, &#123; PluginFunction &#125; <span class="keyword">from</span> <span class="string">'vue'</span>;</span><br><span class="line">  <span class="keyword">const</span> _default: PluginFunction&lt;Vue&gt;;</span><br><span class="line">  <span class="keyword">export</span> <span class="keyword">default</span> _default;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>项目开发相关的 ts 问题可查阅先前的一篇 ts 问题总结篇，配置开发包的 ts 问题看本文的问题汇总。</p>
</blockquote>
<h4 id="Test-测试配置"><a href="#Test-测试配置" class="headerlink" title="Test 测试配置"></a>Test 测试配置</h4><p>demo 内使用的是 Mocha + chai，同时对 slot 部分做了一下测试，这个对着文档就能做出一些测试函数，其余的配置 vue-cli 都封装好了。测试的语法并非本文的重点，有机会可以补上一篇。</p>
<h4 id="单文件打包配置"><a href="#单文件打包配置" class="headerlink" title="单文件打包配置"></a>单文件打包配置</h4><p>要实现按需引入的话，我们还需配置多入口打包。先前规范的 package 文件夹的结构刚好就支持我们遍历需要打包的文件。</p>
<p>由于想稍微偷点懒，这里我就直接用 json 记录各需要的入口文件，同时配置 webpack.components.js 仅用于单独打包。webpack 的详细配置其实可以参考 vue-cli 的内部配置（vue inspect），在此我就不一一列举了，其它需要注意的部分就是如果 package 包内的组件如果用 TS 写的，那么尽量不要压缩代码，可能会出现 name 被压缩的问题了。</p>
<h3 id="文档配置"><a href="#文档配置" class="headerlink" title="文档配置"></a>文档配置</h3><p>对于整个项目来说，文档的配置可以算是一个点缀项，能让整体更加完善。vuepress 文档已经十分详细了，这里仅仅记录一些比较困难的配置点。docs 文件的结构大致为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">vue-cli-project-demo/docs</span><br><span class="line">├── .vuepress</span><br><span class="line">|  ├── config.js</span><br><span class="line">|  ├── enhanceApp.js</span><br><span class="line">|  ├── public</span><br><span class="line">|  |  ├── favicon.ico</span><br><span class="line">|  |  └── logo.jpg</span><br><span class="line">|  ├── router-config.js</span><br><span class="line">|  ├── static-theme-config.js</span><br><span class="line">|  └── utils</span><br><span class="line">|    └── index.js</span><br><span class="line">├── components</span><br><span class="line">|  ├── button.md</span><br><span class="line">|  └── index.md</span><br><span class="line">└── index.md</span><br></pre></td></tr></table></figure>
<blockquote>
<p>注： docs 才是文档页面的根路径。</p>
</blockquote>
<h4 id="图片配置"><a href="#图片配置" class="headerlink" title="图片配置"></a>图片配置</h4><p>Vuepress 内分为文档图片资源和静态图片资源。公共图片资源就不用介绍了，一般相对路径的 markdown 写法能完全满足要求。但是对于页面的 favicon 和首页模板部分的 logo ，这个需要在 .vuepress 下的 public 文件内做存储。</p>
<h4 id="项目包引入"><a href="#项目包引入" class="headerlink" title="项目包引入"></a>项目包引入</h4><p>对于我们生成的 lib 包的引入，此需要在 .vuepress 文件夹下创建一个 enhanceApp.js 文件，在该文件内做额外包的引入。写法为：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 安装发布的包</span></span><br><span class="line"><span class="keyword">import</span> MyComponents <span class="keyword">from</span> <span class="string">'../../lib/vue-cli-project-demo.umd'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> (&#123;</span><br><span class="line">  Vue, <span class="comment">// VuePress 正在使用的 Vue 构造函数</span></span><br><span class="line">  options, <span class="comment">// 附加到根实例的一些选项</span></span><br><span class="line">  router, <span class="comment">// 当前应用的路由实例</span></span><br><span class="line">  siteData <span class="comment">// 站点元数据</span></span><br><span class="line">&#125;) =&gt; &#123;</span><br><span class="line">  Vue.use(MyComponents)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="整体页面配置"><a href="#整体页面配置" class="headerlink" title="整体页面配置"></a>整体页面配置</h4><p>与 .vuepress 同级别的其余文件/文件夹为对应的页面模板，例如：默认进入显示的首页为 index.md 文件，对于各文件的路径配置需要在 .vuepress/config.js 文件内对应编写。</p>
<p>这里可能会遇到的问题是，将 config.js 文件拆分成多个文件时，页面会无法监听到其余 js 配置文件的修改。我们此时需要配置 <code>extraWatchFiles</code> 字段来额外监听需要监听的文件。</p>
<p>另外需要注意的是 <code>base</code> 属性，如果部署在服务器上的路径非根路径，那么此还需要对应设置一下。剩余的配置都为比较基础的配置了，demo 内都有较为详细的说明，在此就不一一列举了。</p>
<h4 id="部署"><a href="#部署" class="headerlink" title="部署"></a>部署</h4><p>因为我的 github.io 上已经有我的博客了，此部分具体有什么坑我也没有踩过，仅能给大家抛个<a href="https://v1.vuepress.vuejs.org/zh/guide/deploy.html#github-pages" target="_blank" rel="noopener">链接</a>了。</p>
<h3 id="Demo-地址"><a href="#Demo-地址" class="headerlink" title="Demo 地址"></a>Demo 地址</h3><p><a href="https://github.com/kazehaiya/vue-cli-project-demo" target="_blank" rel="noopener">传送门</a></p>
<h3 id="问题汇总"><a href="#问题汇总" class="headerlink" title="问题汇总"></a>问题汇总</h3><h4 id="引入打包的-lib-文件报错"><a href="#引入打包的-lib-文件报错" class="headerlink" title="引入打包的 lib 文件报错"></a>引入打包的 lib 文件报错</h4><p>在测试生成的包时，通过 import 引入报错，其原因是 webpack 对于 import 的文件会进行此处的 js 解析，然而对于已经打包好的文件我们预想的是直接引入就行了，因此需要将其从规则中去除掉，否则通过规则去解析就会报错。</p>
<h4 id="两个-types-文件的目的"><a href="#两个-types-文件的目的" class="headerlink" title="两个 types 文件的目的"></a>两个 types 文件的目的</h4><p>项目内的 types 文件其实可以合并成一个，但是个人倾向分成两部分。与 src 同层的 types 文件仅用来声明 lib 默认导出的文件，而 src/types 文件则是项目开发时需要的文件声明。如果最终发布至 npm 上的包仅包含 lib 文件，那么建议使用 demo 的这种写法，层次会更清楚一点。</p>
<h4 id="使用-lib-中的-umd-min-js-文件报错"><a href="#使用-lib-中的-umd-min-js-文件报错" class="headerlink" title="使用 lib 中的 umd.min.js 文件报错"></a>使用 lib 中的 umd.min.js 文件报错</h4><p>由于 lib 打包生成的 min 文件将组件的 Class 名压缩了，因此对应的 name 值就不是我们设置的值，即使将 name 显示至于 Component 内也不行，对此我发了一条 <a href="https://github.com/vuejs/vue-cli/issues/4338" target="_blank" rel="noopener">issue</a></p>
<p>补充： 最终的解决方案有两个，这里列举一下解决思路：</p>
<p>方法 1:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 对应包组件</span></span><br><span class="line">@Component(&#123;</span><br><span class="line">  name: <span class="string">'MyButton'</span></span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> <span class="class"><span class="keyword">class</span> <span class="title">MyButton</span> <span class="keyword">extends</span> <span class="title">Vue</span> </span>&#123;&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">// install 方法内的 component 注册部分</span></span><br><span class="line">Vue.component(MyButton.options.name, MyButton);</span><br></pre></td></tr></table></figure>
<p>方法 2:</p>
<p>配置 terser 的代码压缩部分，令其不压缩 className，该部分在 vue.config.js 内配置如下内容。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">configureWebpack: <span class="function"><span class="params">config</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">if</span> (process.env.NODE_ENV === <span class="string">'production'</span>) &#123;</span><br><span class="line">    config.optimization.minimizer[<span class="number">0</span>].options.terserOptions.keep_fnames = <span class="literal">true</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>注意：</strong> vue-cli 使用的是 terser 而不是 uglify，此外虽然 vue 内有对应 terser 的命名，但是没法获取得到，使用 config.optimization.minimizer(‘terser’) 函数会使得 minimizer 部分的内容丢失，暂未找到比较好的解决方法。个人还是希望官方补充一下解决该问题的思路。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 源码中的 production 环境的部分配置</span></span><br><span class="line"><span class="keyword">if</span> (process.env.VUE_CLI_TEST) &#123;</span><br><span class="line">  webpackConfig.optimization.minimize(<span class="literal">false</span>)</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">  <span class="keyword">const</span> TerserPlugin = <span class="built_in">require</span>(<span class="string">'terser-webpack-plugin'</span>)</span><br><span class="line">  <span class="keyword">const</span> terserOptions = <span class="built_in">require</span>(<span class="string">'./terserOptions'</span>)</span><br><span class="line">  webpackConfig.optimization</span><br><span class="line">    .minimizer(<span class="string">'terser'</span>)</span><br><span class="line">      .use(TerserPlugin, [terserOptions(options)])</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>源码请见 <a href="https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/config/prod.js" target="_blank" rel="noopener">prod.js</a><br>官方 <a href="https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/config/terserOptions.js" target="_blank" rel="noopener">terserOptions</a> 配置</p>
</blockquote>
<h4 id="install-方法报错"><a href="#install-方法报错" class="headerlink" title="install 方法报错"></a>install 方法报错</h4><p>在对应包的 index.ts 内为导出的包设置 install 方法时报错，install 方法在 Vue 中是作为 Plugins 的一个内置函数而设置的，而我们导出的实例类型为 VueConstructor ，在 VueConstructor 上并没有 install 函数，因此按照 plugins 那种写法扩展声明一个即可。</p>
<h4 id="引入包的项目构建页面不呈现"><a href="#引入包的项目构建页面不呈现" class="headerlink" title="引入包的项目构建页面不呈现"></a>引入包的项目构建页面不呈现</h4><p>使用 <code>Components</code> 语法编写的组件库可能会遇到这么一个问题，项目将组件通过 <code>Vue.use</code> 方法全量注册到项目中了，开发环节并没有遇到任何问题，可随处使用，但是一旦 <code>build</code> 构建后，页面却无法呈现出组件。</p>
<p><strong>原因：</strong> <code>Class</code> 语法编写的组件编译时会经有 <code>vue-cli</code> 的 webpack 处理，默认的 <code>terser</code> 压缩配置中同样会将 <code>ClassName</code> 给压缩掉，这就导致引入的组件在生产环境找不到了。</p>
<blockquote>
<p>解决方法：参考 <strong>使用 lib 中的 umd.min.js 文件报错</strong> 的 <strong>方法 2</strong></p>
</blockquote>
<h3 id="参考文档"><a href="#参考文档" class="headerlink" title="参考文档"></a>参考文档</h3><ul>
<li><a href="/2019/04/14/发布一个-vue-包/" title="发布一个 vue 包">发布一个 vue 包</a></li>
<li><a href="/2019/07/14/项目-ts-迁移的踩坑记录/" title="项目 ts 迁移的踩坑记录">项目 ts 迁移的踩坑记录</a></li>
<li><a href="https://github.com/typescript-eslint/typescript-eslint#readme" target="_blank" rel="noopener">typescript-eslint/typescript-eslint</a></li>
<li><a href="https://cli.vuejs.org/zh/guide/" target="_blank" rel="noopener">vue-cli 文档</a></li>
<li><a href="https://v1.vuepress.vuejs.org/zh/guide/" target="_blank" rel="noopener">vuepress 文档</a></li>
<li><a href="https://www.cnblogs.com/zaihuilou/p/9556373.html" target="_blank" rel="noopener">TS 编译选项查询表</a></li>
<li><a href="https://www.chaijs.com/" target="_blank" rel="noopener">Chai.js 文档</a></li>
<li><a href="https://medium.com/haiiro-io/element-component-name-with-vue-class-component-f3b435656561" target="_blank" rel="noopener">Element/Component name with vue-class-component</a></li>
</ul>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>蔡胤
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://monocy.gitee.io/2019/07/11/使用-vue-cli-发布一个完善的包/" title="使用 vue-cli 发布一个完善的包">https://monocy.gitee.io/2019/07/11/使用-vue-cli-发布一个完善的包/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/Vue/" rel="tag"><i class="fa fa-tag"></i> Vue</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2019/07/07/由-shims-vue-d-ts-引发的思考/" rel="prev" title="由 shims-vue.d.ts 引发的思考">
      <i class="fa fa-chevron-left"></i> 由 shims-vue.d.ts 引发的思考
    </a></div>
      <div class="post-nav-item">
    <a href="/2019/07/14/项目-ts-迁移的踩坑记录/" rel="next" title="项目 ts 迁移的踩坑记录">
      项目 ts 迁移的踩坑记录 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#目标"><span class="nav-number">2.</span> <span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#项目环境构建"><span class="nav-number">3.</span> <span class="nav-text">项目环境构建</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#TS-的-Class-风格支持"><span class="nav-number">3.1.</span> <span class="nav-text">TS 的 Class 风格支持</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#TS-使用-eslint-standard"><span class="nav-number">3.2.</span> <span class="nav-text">TS 使用 eslint-standard</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#其余部分"><span class="nav-number">3.3.</span> <span class="nav-text">其余部分</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#项目配置"><span class="nav-number">4.</span> <span class="nav-text">项目配置</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#结构配置"><span class="nav-number">4.1.</span> <span class="nav-text">结构配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#配置-tsconfig-json-和-vue-config-js"><span class="nav-number">4.2.</span> <span class="nav-text">配置 tsconfig.json 和 vue.config.js</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#packages-包写法"><span class="nav-number">4.3.</span> <span class="nav-text">packages 包写法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#打包配置"><span class="nav-number">4.4.</span> <span class="nav-text">打包配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#dev-环境配置"><span class="nav-number">4.5.</span> <span class="nav-text">dev 环境配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Test-测试配置"><span class="nav-number">4.6.</span> <span class="nav-text">Test 测试配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#单文件打包配置"><span class="nav-number">4.7.</span> <span class="nav-text">单文件打包配置</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#文档配置"><span class="nav-number">5.</span> <span class="nav-text">文档配置</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#图片配置"><span class="nav-number">5.1.</span> <span class="nav-text">图片配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#项目包引入"><span class="nav-number">5.2.</span> <span class="nav-text">项目包引入</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#整体页面配置"><span class="nav-number">5.3.</span> <span class="nav-text">整体页面配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#部署"><span class="nav-number">5.4.</span> <span class="nav-text">部署</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Demo-地址"><span class="nav-number">6.</span> <span class="nav-text">Demo 地址</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#问题汇总"><span class="nav-number">7.</span> <span class="nav-text">问题汇总</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#引入打包的-lib-文件报错"><span class="nav-number">7.1.</span> <span class="nav-text">引入打包的 lib 文件报错</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#两个-types-文件的目的"><span class="nav-number">7.2.</span> <span class="nav-text">两个 types 文件的目的</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用-lib-中的-umd-min-js-文件报错"><span class="nav-number">7.3.</span> <span class="nav-text">使用 lib 中的 umd.min.js 文件报错</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#install-方法报错"><span class="nav-number">7.4.</span> <span class="nav-text">install 方法报错</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#引入包的项目构建页面不呈现"><span class="nav-number">7.5.</span> <span class="nav-text">引入包的项目构建页面不呈现</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#参考文档"><span class="nav-number">8.</span> <span class="nav-text">参考文档</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="蔡胤"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">蔡胤</p>
  <div class="site-description" itemprop="description">Just do IT!</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">61</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">15</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">31</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/kazehaiya" title="GitHub → https://github.com/kazehaiya" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:c763416559@163.com" title="Mail → mailto:c763416559@163.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/Nora_Monocy" title="Weibo → https://weibo.com/Nora_Monocy" rel="noopener" target="_blank"><i class="fab fa-weibo fa-fw"></i></a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://liujinkai.com/" title="http://liujinkai.com/" rel="noopener" target="_blank">凯凯刘</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://weekly.75team.com/" title="https://weekly.75team.com/" rel="noopener" target="_blank">奇舞周刊</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://75.team/post/list" title="https://75.team/post/list" rel="noopener" target="_blank">奇舞团博客</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://tech.meituan.com/" title="https://tech.meituan.com/" rel="noopener" target="_blank">美团技术团队</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://tech.youzan.com/" title="https://tech.youzan.com/" rel="noopener" target="_blank">有赞技术团队</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://kalacloud.com" title="https://kalacloud.com" rel="noopener" target="_blank">卡拉云</a>
        </li>
    </ul>
  </div>

      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><a href="https://beian.miit.gov.cn" rel="noopener" target="_blank">京ICP备2020036147号-1 </a>
      <img src="/images/beian.png" style="display: inline-block;"><a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=42011702000651" rel="noopener" target="_blank">鄂公网安备 42011702000651 号 </a>
  </div>

<div class="copyright">
  
  &copy; 2018 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-dragon"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">蔡胤</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">101k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">1:32</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/theme-next/theme-next-pjax@0/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/medium-zoom@1/dist/medium-zoom.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script>
<script src="/js/schemes/pisces.js"></script>
<script src="/js/next-boot.js"></script>
  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '.languages',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[data-pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.dataset.pjax !== undefined) {
      script.dataset.pjax = '';
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  




  <script src="/js/local-search.js"></script>












    <div id="pjax">
  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/valine@1/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : true,
      notify     : true,
      appId      : 'GkgJm97N3UFm2mRb1eFcP2dn-gzGzoHsz',
      appKey     : 'kJ8tYUUkX4ifhWha8rjnxWS8',
      placeholder: "请不要吝惜你的笔头，来说点什么吧！",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : true,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

    </div>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/Epsilon2.1.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true,"scale":0.5},"react":{"opacity":0.7},"log":false});</script></body>
</html>
